﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Web;
using jsm.SqlHelper;

namespace dbcaac
{
	/// <summary>
	/// 所有数据实体的基类
	/// </summary>
	public abstract class EntityBase
	{
        //protected string m_sql = null;
        //protected List<SqlParameter> m_params = new List<SqlParameter>();

        public virtual string isValid() { return null; }

        public virtual string getIdField() { return null; }
        public virtual string getPidField() { return null; }
        public virtual int getTotal() { return 0; }

        public abstract void loadPageData(HttpContext context);

        protected abstract int doInsertOperation();             // 增
        protected abstract int doDeleteOperation();             // 删
        protected abstract int doUpdateOperation();             // 改
        public abstract SqlDataReader executeDataReader();      // 查


        public virtual int executePageAction(string action)
        {
            int r = 0;
            if ("INSERT" == action.ToUpper())
            {
                r = doInsertOperation();
            }
            else if ("UPDATE" == action.ToUpper())
            {
                r = doUpdateOperation();
            }
            else if ("DELETE" == action.ToUpper())
            {
                r = doDeleteOperation();
            }
            else
            {
                ExceptionHelper.Throw404Exception();
            }
            return r;
        }
   }
}
